<!-- error -->
<script type="text/javascript">
        function addFields() {
                dataCount=3;
                dataCount++;
                var d = document.getElementById("ItemAddForm");
                d.innerHTML += "<input type='file' name='data[Photo][" + dataCount + "][name]' id='Photo" + dataCount + "name'>";
        }
</script>


<div class="admin_left actions">
        <h3 style="font-size:20px;">Manage more</h3>
        <ul>
            <li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Items'), array('action' => 'index'),array('class' => 'consistentButton')); ?> </li>
             </ul>
    </div>





<div class="admin_right">
    <?php if ($current_customer['group_id'] == 1): ?>
    
		    <div id=breadcrumbAdmin>
		        <?php $this->Html->addCrumb('Add item', '/Items/add', array('style'=> ('text-decoration:underline;  color:#EB1E70;'))); ?>
		        <?php echo $this->Html->getCrumbs(' > ', array( 'text' => 'Items', 'url' => array('controller' => 'items', 'action' => 'index'), 'escape' => false)); ?>
		    </div>
		    
            <div class="items form">
                <?php echo $this->Form->create('Item',array('type'=>'file')); ?>
                        <fieldset>
                                <legend><?php echo __('Add Item'); ?></legend>
                        <?php
                                echo $this->Form->input('Item.name');
                                $is_consignments = array('Consignment' => 'Consignment', 'normal' => 'normal');
                                echo $this->Form->input('Item.is_consignment', array('options' => $is_consignments, 'default' => 'normal'));
                                echo $this->Form->input('Item.brand_id');
                                echo $this->Form->button('Add brand', array('type'=> 'button', 'class' => 'brand-popup-window'));
                                echo $this->Form->input('Item.color_id');
                                echo $this->Form->button('Add colour', array('type'=> 'button', 'class' => 'color-popup-window'));
                                echo $this->Form->input('Item.condition_id');
                                echo $this->Form->button('Add condition', array('type'=> 'button', 'class' => 'condition-popup-window'));
                                echo $this->Form->input('Item.size_id');
                                echo $this->Form->button('Add size', array('type'=> 'button', 'class' => 'size-popup-window'));
                                echo $this->Form->input('Item.category_id');
                                echo $this->Form->button('Add category', array('type'=> 'button', 'class' => 'category-popup-window'));
                                echo $this->Form->input('Item.item_status_id');
                                echo $this->Form->input('description');
                                $onlines = array('Yes' => 'Yes', 'No' => 'No');
                                echo $this->Form->input('Item.online', array('options' => $onlines, 'default' => 'No'));
                                $locations = array_combine( array('Backstorage', 'On Display'),array('Backstorage', 'On Display'));
                                echo $this->Form->input('Item.location', array('options' => $locations, 'default' => 'Backstorage'));
                                echo $this->Form->input('Item.original_price');
                                $is_discounted = array('Yes' => 'Yes', 'No' => 'No');
                                echo $this->Form->input('Item.is_discounted', array('options' => $is_discounted, 'default' => 'No'));
                                //echo $this->Form->input('image_id');
                                echo $this->Form->input('Image.0.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.1.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.2.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.3.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.4.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.5.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.6.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                echo $this->Form->input('Image.7.name', array('label' => false, 'div' => false, 'type' => 'file'));
                                //echo "<input type='button' id='more-fields' onclick='addFields();' value='Add more images' />";
                        ?>
                        </fieldset>
                <?php echo $this->Form->end(__('Submit')); ?>
            </div>

<script type="text/javascript">

    $(document).ready(function() {

        $('.brand-popup-window').click(function(){

           var popupBoxBrand = '#popup-box-brand';

           $(popupBoxBrand).fadeIn(400);

           var popMargTop = ($(popupBoxBrand).height() + 24) /2;
           var popMargLeft = ($(popupBoxBrand).height() + 24) /2;

           $(popupBoxBrand).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });

        $('.color-popup-window').click(function(){

           var popupBoxColor = '#popup-box-color';

           $(popupBoxColor).fadeIn(400);

           var popMargTop = ($(popupBoxColor).height() + 24) /2;
           var popMargLeft = ($(popupBoxColor).height() + 24) /2;

           $(popupBoxColor).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });

        $('.condition-popup-window').click(function(){

           var popupBoxCondition = '#popup-box-condition';

           $(popupBoxCondition).fadeIn(400);

           var popMargTop = ($(popupBoxCondition).height() + 24) /2;
           var popMargLeft = ($(popupBoxCondition).height() + 24) /2;

           $(popupBoxCondition).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });


        $('.size-popup-window').click(function(){

           var popupBoxSize = '#popup-box-size';

           $(popupBoxSize).fadeIn(400);

           var popMargTop = ($(popupBoxSize).height() + 24) /2;
           var popMargLeft = ($(popupBoxSize).height() + 24) /2;

           $(popupBoxSize).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });

        $('.category-popup-window').click(function(){

                   var popupBoxCategory = '#popup-box-category';

                   $(popupBoxCategory).fadeIn(400);

                   var popMargTop = ($(popupBoxCategory).height() + 24) /2;
                   var popMargLeft = ($(popupBoxCategory).height() + 24) /2;

                   $(popupBoxCategory).css({
                    'margin-top' : -popMargTop,
                    'margin-left' : -popMargLeft
                   });

                   $('body').append('<div id="mask"></div>');
                   $('#mask').fadeIn(400);
                   return false;

        });

        $('button.close, #mask').bind('click', function(){
            $('#mask, .popupInfo').fadeOut(400, function(){
                $('#mask').remove();
            });
            return false;

        });




    });

$(document).keyup(function(e) {
    if ( e.keyCode == 27) {
        $('#mask, .popupInfo, #popup-box-brand, #popup-box-color, #popup-box-condition, #popup-box-size, #popup-box-category').fadeOut(400);
        return false;
    }
});

//not working part
$('#mask').onclick(function(){
        $('#mask, .popupInfo, #popup-box-brand, #popup-box-color, #popup-box-condition, #popup-box-size, #popup-box-category').fadeOut(400);
});
//not working part

</script>










<!-- popup button for brand begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-brand" class="popupInfo">
	<?php echo $this->Form->create('Brand',array("url"=>array("controller"=>"brands"))); ?>
	<h4>New Brand:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
	<?php echo $this->Form->input("name",array("type"=>"text")); ?>
	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>
</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#BrandAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
				 $("#ItemBrandId").empty();
				 $.each(data.brandlist,function(index,elem){
					 $("#ItemBrandId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#BrandAddForm #BrandName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for brand ends -->





<!-- popup button for color begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-color" class="popupInfo">
	<?php echo $this->Form->create('Color',array("url"=>array("controller"=>"colors"))); ?>
	<h4>New Colour:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="randomColor" style="height:25px;" />
	<?php echo $this->Form->input("name",array("type"=>"text")); ?>
	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>
</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#ColorAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 if(data.status){
				 $("#ItemColorId").empty();
				 $.each(data.colorlist,function(index,elem){
					 $("#ItemColorId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#ColorAddForm #ColorName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for color ends -->






<!-- popup button for condition begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-condition" class="popupInfo">
	<?php echo $this->Form->create('Condition',array("url"=>array("controller"=>"conditions"))); ?>
	<h4>New Condition:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="randomCondition" style="height:25px;" />
	<?php echo $this->Form->input("name",array("type"=>"text")); ?>
	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>
</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#ConditionAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 if(data.status){
				 $("#ItemConditionId").empty();
				 $.each(data.conditionlist,function(index,elem){
					 $("#ItemConditionId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#ConditionAddForm #ConditionName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for condition ends -->






<!-- popup button for size begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-size" class="popupInfo">
	<?php echo $this->Form->create('Size',array("url"=>array("controller"=>"sizes"))); ?>
	<h4>New Size:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
	<?php echo $this->Form->input("size_value",array("type"=>"text")); ?>
	<?php echo $this->Form->input("size_unit",array("type"=>"text")); ?>
	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>
</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#SizeAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
				 $("#ItemSizeId").empty();
				 $.each(data.sizelist,function(index,elem){
					 $("#ItemSizeId").append("<option value="+elem.id+">"+elem.size_value+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#SizeAddForm #SizeSizeValue #SizeSizeUnit").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for size ends -->





<!-- popup button for category begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-category" class="popupInfo" >
	<?php echo $this->Form->create('Category',array("url"=>array("controller"=>"categories"))); ?>
	<h4>New Category:</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="randomCategory" style="height:25px;" />
	<?php echo $this->Form->input("name",array("type"=>"text")); ?>
	<?php echo $this->Form->input("description",array("type"=>"text")); ?>
	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>
</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#CategoryAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 if(data.status){
				 $("#ItemCategoryId").empty();
				 $.each(data.categorylist,function(index,elem){
					 $("#ItemCategoryId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#CategoryAddForm #CategoryName #CategoryDescription").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for category ends -->




    <?php else: ?>
        <?php echo "You can't view this page"; ?>
    <?php endif; ?>
</div>